package com.study.dao;

import java.util.List;

import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.study.bean.ImgBean;
import com.study.bean.PictureBean;
import com.study.bean.courseBean;
import com.study.bean.scBean;
import com.study.db.BasicDataOperation;
import com.study.tools.MyTools;

public class AddCarItemDao {
	/**
	 * @查询要加入购物车的商品信息
	 */
	public List<courseBean> getInfo(courseBean pcou) {
		String sql = "select * from course where C_NAME=? and C_PRICE=?";
		List<courseBean> list = MyTools.getInstance(BasicDataOperation.class).query(sql,
				new BeanListHandler<>(courseBean.class), pcou.getC_NAME(), pcou.getC_PRICE());
		return list;
	}

	/**
	 * @param 把要加入购物车的商品信息放到数据库
	 * @return
	 */
	public int getInfosc(scBean sc) {
		String sql = "insert into sc(host_id,c_id,sc_tag) values (?,?,?)";
		int i = MyTools.getInstance(BasicDataOperation.class).upade(sql, sc.getHost_id(), sc.getC_id(), sc.getSc_tag());
		return i;
	}

	/**
	 * @param 利用pic进行查询操作，准备把商品信息显示在我的购物车页面中
	 * @return
	 */
	public List<PictureBean> getpictureInfo(PictureBean pcou) {
		String sql = "select sc.c_id,c_img,c_name,c_price from sc ,course  where sc.c_id=course.c_id and sc.host_id=? and sc.sc_tag=0";
		List<PictureBean> list = MyTools.getInstance(BasicDataOperation.class).query(sql,
				new BeanListHandler<>(PictureBean.class), pcou.getHost_id());
		return list;
	}

	/**
	 * @param 在首页加入图片
	 * @return
	 */
	public List<ImgBean> getimgInfo(ImgBean pcou) {
		String sql = "select c_img,c_name from course where c_tag=1";
		List<ImgBean> list = MyTools.getInstance(BasicDataOperation.class).query(sql,
				new BeanListHandler<>(ImgBean.class));
		return list;
	}

	public int getdeleteInfoto(ImgBean pcou) {
		String sql = "delete  from sc  where sc_tag = 0 and host_id = ? and c_id = ?";
		int list = MyTools.getInstance(BasicDataOperation.class).upade(sql,
				pcou.getHost_id(), pcou.getC_id());
		return list;
	}
	public int getdeleteInfotogengxin(scBean pcou) {
		String sql = "update sc set sc_tag=1 where host_id=? and c_id=? ";
		int list = MyTools.getInstance(BasicDataOperation.class).upade(sql,
				pcou.getHost_id(), pcou.getC_id());
		return list;
	}
	
	public List<PictureBean>  getdeleteInfotoafford(PictureBean pcou) {
		String sql ="select sc.c_id,c_img,c_name,c_price from sc ,course  where sc.c_id=course.c_id and sc.host_id=? and sc.sc_tag=1";
		List<PictureBean>  list = MyTools.getInstance(BasicDataOperation.class).query(sql, new BeanListHandler<>(PictureBean.class),pcou.getHost_id());
		return list;
	}
}
